package com.huawei.esdk.uc.sametime.widgets;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import org.apache.log4j.Logger;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.MenuListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.events.ShellListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Widget;

import com.huawei.esdk.uc.jna.Constants;
import com.huawei.esdk.uc.jna.UCService;
import com.huawei.esdk.uc.jna.Constants.AccountType;
import com.huawei.esdk.uc.jna.Constants.ContactAvailability;
import com.huawei.esdk.uc.jna.Constants.ConvnerOperateType;
import com.huawei.esdk.uc.jna.Constants.MemStatusInCall;
import com.huawei.esdk.uc.jna.Constants.PhoneJointType;
import com.huawei.esdk.uc.jna.Constants.UCServiceRetvCode;
import com.huawei.esdk.uc.jna.mode.VideoFrameParmas;
import com.huawei.esdk.uc.jna.struct.STConfParam;
import com.huawei.esdk.uc.jna.struct.STVideoWindow;
import com.huawei.esdk.uc.jna.util.StringUtil;
import com.huawei.esdk.uc.sametime.ConstantsDefines;
import com.huawei.esdk.uc.sametime.ConstantsDefines.CallMode;
import com.huawei.esdk.uc.sametime.ConstantsDefines.CallStatus;
import com.huawei.esdk.uc.sametime.history.ui.EsdkUCHistoryView;
import com.huawei.esdk.uc.sametime.international.Messages;
import com.huawei.esdk.uc.sametime.models.Participant;
import com.huawei.esdk.uc.sametime.models.ParticipantList;
import com.huawei.esdk.uc.sametime.services.UCCallService;
import com.huawei.esdk.uc.sametime.services.UCConfService;
import com.huawei.esdk.uc.sametime.services.UCHistoryService;
import com.huawei.esdk.uc.sametime.services.UCSettingsService;
import com.huawei.esdk.uc.sametime.util.ImageFactory;
import com.huawei.esdk.uc.sametime.util.PersonInviteUtil;
import com.huawei.esdk.uc.sametime.util.PluginUtil;
import com.ibm.collaboration.realtime.chatwindow.ChatWindowHandler;
import com.ibm.collaboration.realtime.people.PeopleUtil;
import com.ibm.collaboration.realtime.people.Person;

/**
 * 创建通话弹窗的单例类
 * 
 * @author lWX169831
 * 
 */
public class EsdkUCConvWindow
{
    private static Logger logger = Logger.getLogger(EsdkUCConvWindow.class);

    private static EsdkUCConvWindow instance;

    private Composite composite;

    private ChatWindowHandler handler = null;

    private ToolBar toolBar;

    private ToolItem videoOpenItem;

    private ToolItem holdItem;

    private ToolItem contactAddItem;

    private Label timeLabel;

    private FormData fd;

    private Table table;

    private TableViewer tableViewer;

    private Label divider_1;

    private Group videoArea;

    private Label localVideo;

    private Label remoteVideo;

    // 通话窗口底部的状态栏标签
    private Label statusBar;

    private boolean isVideo = false;

    private boolean isConf = false;

    private boolean isHold = false;

    private boolean isMute = false;

    private ParticipantList participants;

    private Map<String, Participant> participantsMap = new HashMap<String, Participant>();;

    private VideoFrameParmas videoParmas;

    private static final int IS_CHAIRMAN_COLUMN = 0;

    private static final int UC_STATUS_COLUMN = 1;

    private static final int PARTI_COLUMN = 2;

    private static final int NUMBER_COLUMN = 3;

    private static final int COLUMN_COUNT = 4;

    private static final String CHATWINDOWCONVPOPUPADDON = "com.huawei.esdk.uc.sametime.chatwindow.chatwindowConvPopupAddOn"; //$NON-NLS-1$

    private Timer callTimer;

    private long callTimes;

    // 二次拨号盘的工具栏项
    private ToolItem secondDialPadItem;

    private SecondDialPad secondDialPad;

    // 静音工具栏按钮项
    private ToolItem muteItem;

    private EsdkUCConvWindow()
    {

    }

    public synchronized static EsdkUCConvWindow getInstance()
    {
        if (null == instance)
        {
            instance = new EsdkUCConvWindow();
        }
        return instance;
    }

    public void createUCConvWindow(ParticipantList participantList)
    {
        if (isDisposed(composite))
        {
            participants = participantList;

            syncParticipantsMap();
            composite = new Shell(SWT.CLOSE | SWT.MIN);
            composite.setSize(400, 200);
            handler = null;
            setShellClosedListen();
        }
    }

    public void createUCConvWindow(ParticipantList participantList,
            Composite parent, ChatWindowHandler handler)
    {
        if (isDisposed(composite))
        {
            participants = participantList;
            syncParticipantsMap();
            composite = new Composite(parent, SWT.WRAP);
            this.handler = handler;
            setCompositeDisposeListener();

            setChatShellListener(handler);
        }
    }

    private void setChatShellListener(final ChatWindowHandler handler)
    {
        composite.addControlListener(new ControlListener()
        {

            @Override
            public void controlMoved(ControlEvent arg0)
            {
            }

            @Override
            public void controlResized(ControlEvent arg0)
            {
                freshTable();
            }
        });

        handler.getShell().addControlListener(new ControlListener()
        {

            @Override
            public void controlMoved(ControlEvent arg0)
            {
            }

            @Override
            public void controlResized(ControlEvent arg0)
            {
                freshTable();
            }
        });
    }

    /**
     * 初始化存储通话联系人的Map
     */
    private void syncParticipantsMap()
    {
        participantsMap.clear();
        int size = participants.size();
        Participant participant = null;
        for (int i = 0; i < size; i++)
        {
            participant = participants.getparticipants().get(i);
            participantsMap.put(participant.getUcAccount(), participant);
        }
    }

    /**
     * 添加窗口关闭的监听
     */
    private void setShellClosedListen()
    {
        composite.getShell().addShellListener(new ShellListener()
        {
            @Override
            public void shellActivated(ShellEvent arg0)
            {
            }

            @Override
            public void shellClosed(ShellEvent arg0)
            {
                logger.debug("shell closed");
                if (MessageDialog.openConfirm(composite.getShell(),
                        Messages.TIPS,
                        Messages.EsdkUCConvWindow_HUNGUPCALLPROMPT))
                {
                    arg0.doit = true;
                    endCall();
                }
                else
                {
                    arg0.doit = false;
                }
            }

            @Override
            public void shellDeactivated(ShellEvent arg0)
            {
            }

            @Override
            public void shellDeiconified(ShellEvent arg0)
            {
            }

            @Override
            public void shellIconified(ShellEvent arg0)
            {
            }
        });
    }

    private void setCompositeDisposeListener()
    {
        composite.addDisposeListener(new DisposeListener()
        {
            @Override
            public void widgetDisposed(DisposeEvent arg0)
            {
                if (CallStatus.end != UCCallService.getCallStatus())
                {
                    // 这里调用UC SDK的结束呼叫服务接口
                    UCCallService.endCall();
                    setCallEndData();
                }
            }
        });
    }

    private void exeUCService()
    {
        logger.debug("start call or conference conversation");
        if (isConf)
        {
            // 这里调用UC SDK 创建即时会议服务接口
            boolean result = UCConfService.createConference(participants);
            if (!result)
            {
                logger.error("start conference conversation fail");
                MessageDialog.openError(null, Messages.ERROR_TIP,
                        Messages.EsdkUCConvWindow_ERROR_CONF_CREATE_FAIL);
            }
        }
        else if (isVideo)
        {
            // 这里调用UC SDK的发起VoIP呼叫服务（呼叫方式：视频）
            Participant person = participants.getparticipants().get(0);
            boolean result = UCCallService.startVideoCall(person, videoParmas);
            if (!result)
            {
                logger.error("start video call conversation fail");
                MessageDialog.openError(null, Messages.ERROR_TIP,
                        Messages.EsdkUCConvWindow_ERROR_CALL_FAIL);
            }
        }
        else
        {
            // 这里调用UC SDK的发起VoIP呼叫服务（呼叫方式：语音）
            boolean result = UCCallService.startCall(participants);
            if (!result)
            {
                logger.error("start voice call conversation fail");
                MessageDialog.openError(null, Messages.ERROR_TIP,
                        Messages.EsdkUCConvWindow_ERROR_CALL_FAIL);
            }
        }
    }

    private void setConentTitle()
    {
        StringBuffer title = new StringBuffer();
        if (isConf)
        {
            title.append(participants.getparticipants().get(0).getNickname());
            title.append(Messages.EsdkUCConvWindow_CONVERSATION_MULTI_TITLE);
        }
        else
        {
            if (CallMode.callOut == UCCallService.getCallMode())
            {
                title.append(PeopleUtil.getLocalPerson().getDisplayName());
            }
            else
            {
                title.append(participants.getparticipants().get(0)
                        .getNickname());
            }
            title.append(Messages.EsdkUCConvWindow_CONVERSATION_TITLE);
        }

        if (!isDisposed(composite) && composite instanceof Shell)
        {
            composite.getShell().setText(title.toString().trim());
        }
    }

    /**
     * Create contents of the window.
     */
    private void createContent()
    {
        logger.debug("createContent");
        if (null != composite)
        {
            composite.setLayout(new FormLayout());

            createStatusbar();

            if (null == toolBar)
            {
                createCallControlToolBar();
            }

            if (null == timeLabel)
            {
                createTimeLabel();
            }

            // Dark line separator between business card and text area.
            divider_1 = createDividerLabel(toolBar);

            if (null == tableViewer)
            {
                createPartiListTable();
            }

            if (isVideo)
            {
                if (isDisposed(videoArea))
                {
                    createVideoControl();
                }
                addVideoScreenArea();
            }

            setConfEnabled(isConf);

            setVideoEnabled(isVideo);

            composite.pack();
            composite.layout();
        }
    }

    public void makeCall(boolean isVideo)
    {
        logger.debug("make call isVideo = " + isVideo);
        if (null != composite)
        {
            UCCallService.setCallStatus(CallStatus.calling);
            this.isVideo = isVideo;
            createContent();
            setStatusTip(Messages.EsdkUCConvWindow_CALL_CONNECTING);
            exeUCService();
            setConentTitle();
            composite.getShell().open();
        }
    }

    public void acceptCall(boolean isVideo)
    {
        logger.debug("acceptCall");
        if (null != composite)
        {
            UCCallService.setCallStatus(CallStatus.connected);
            callStart();

            this.isVideo = isVideo;
            createContent();
            setConentTitle();
            setStatusTip(Messages.EsdkUCConvWindow_CALL_CONNECTED);

            if (!isVideo)
            {
                if (Constants.UCServiceRetvCode.UC_SDK_Success == UCService
                        .getInstance().UC_SDK_AcceptCall())
                {
                    composite.getShell().open();
                }
            }
            else
            {
                if (Constants.UCServiceRetvCode.UC_SDK_Success == UCService
                        .getInstance().UC_SDK_AcceptVideoCall(videoParmas))
                {
                    addVideoScreenArea();
                    composite.getShell().open();
                }
            }
        }
    }

    public void connectedForPhone(boolean isVideo)
    {
        if (null != composite)
        {
            UCCallService.setCallStatus(CallStatus.connected);
            callStart();

            this.isVideo = isVideo;
            createContent();
            setConentTitle();
            setStatusTip(Messages.EsdkUCConvWindow_CALL_CONNECTED);

            composite.getShell().open();
        }
    }

    public void openChatContent()
    {
        if (null != composite)
        {
            createContent();
            exeUCService();
        }
    }

    public void closeContents()
    {
        if (null != composite)
        {
            logger.debug("try to close EsdkUCConvWindow");

            if (handler != null)
            {

                handler.closePopup(CHATWINDOWCONVPOPUPADDON);
                handler = null;
            }
            else
            {
                composite.dispose();
            }
        }

        setCallEndData();
    }

    private void setCallEndData()
    {
        logger.debug("setCallEndData");

        if (null == composite)
        {
            return;
        }
        Participant participant = participants.getparticipants().get(0);
        if (null != participant)
        {
            if (isConf)
            {
                String leaderAccount = participant.getUcAccount();
                String leaderName = participant.getNickname();

                UCHistoryService.insertConvHistory(leaderAccount, leaderName,
                        (int) callTimes, participants);

                if (null != EsdkUCHistoryView.getInstance())
                {
                    EsdkUCHistoryView.getInstance().freshConvHistory();
                }
            }
            else
            {
                int ret = UCHistoryService.insertCallHistory(participant
                        .getUcAccount(), participant.getNumber(),
                        (int) callTimes);
                if (UCServiceRetvCode.UC_SDK_Success == ret
                        && null != EsdkUCHistoryView.getInstance())
                {
                    EsdkUCHistoryView.getInstance().freshCallHistory();
                }
            }
        }

        UCCallService.setCallMode(CallMode.invalid);
        UCCallService.setCallStatus(CallStatus.end);

        // 发布自己的状态
        UCService.getInstance().UC_SDK_PubSelfStatus(
                ContactAvailability.Online, "");
        PeopleUtil.getLocalPerson().refreshStatus();

        callStop();

        isVideo = false;
        isConf = false;

        composite = null;

        releaseInstance();
    }

    private synchronized static void releaseInstance()
    {
        instance = null;
    }

    private Label createDividerLabel(Control topControl)
    {
        Label divider = new Label(composite, SWT.NONE);
        divider.setBackground(divider.getDisplay().getSystemColor(
                SWT.COLOR_DARK_GRAY));
        fd = new FormData();
        fd.top = new FormAttachment(topControl, 0);
        fd.left = new FormAttachment(0, 0);
        fd.right = new FormAttachment(100, 0);
        fd.height = 1;
        divider.setLayoutData(fd);
        return divider;
    }

    private void createCallControlToolBar()
    {
        // 创建呼叫控制工具栏对象，使用SWT.RIGHT样式
        toolBar = new ToolBar(composite, SWT.RIGHT);
        toolBar.forceFocus();

        // 暂时不做
        // if (PhoneJointType.IPPhone_Device ==
        // GlobalConfiguration.getInstance()
        // .getCallDevice())
        // {
        // // 创建”更多“工具按钮,定义为下拉式
        // final ToolItem moreItem = new ToolItem(toolBar, SWT.PUSH);
        // moreItem.setToolTipText(Messages.EsdkUCConvWindow_ADD_CONTACT);
        // moreItem.setImage(ImageFactory.loadImage(Display.getCurrent(),
        // ImageFactory.MORE));
        // moreItem.setDisabledImage(ImageFactory.loadImage(Display
        // .getCurrent(), ImageFactory.MORE_DISABLED));
        // final Menu moreMenu = new Menu(composite.getShell(), SWT.POP_UP);
        // MenuItem PCItem = new MenuItem(moreMenu, SWT.PUSH);
        // PCItem.setText(Messages.EsdkUCConvWindow_GO_TO_PC);
        // PCItem.addSelectionListener(new SelectionAdapter()
        // {
        // @Override
        // public void widgetSelected(SelectionEvent arg0)
        // {
        // // 转到 PC
        // }
        // });
        // // 为”更多“下拉工具栏注册单击下拉箭头事件
        // moreItem.addListener(SWT.Selection, new Listener()
        // {
        // @Override
        // public void handleEvent(Event event)
        // {
        // // 如果触发的事件为单击按钮,获得”添加联系人“按钮所在坐标位置和大小，相对于父窗口
        // Rectangle rect = moreItem.getBounds();
        // Point pt = new Point(rect.x, rect.y + rect.height);// 计算菜单出现的起始位置
        // pt = toolBar.toDisplay(pt);// 将该点转化为于屏幕的相对位置
        // moreMenu.setLocation(pt.x, pt.y);// 设置菜单显示的位置
        // moreMenu.setVisible(true);// 显示菜单
        // }
        // });
        // }

        // 创建"保持"工具按扭
        holdItem = new ToolItem(toolBar, SWT.CHECK);
        holdItem.setToolTipText(Messages.EsdkUCConvWindow_HOLD_RELEASE);
        holdItem.setImage(ImageFactory.loadImage(Display.getCurrent(),
                ImageFactory.CALL_HOLD));
        holdItem.setDisabledImage(ImageFactory.loadImage(Display.getCurrent(),
                ImageFactory.CALL_HOLD_DISABLED));
        addHoldItemListener(holdItem);

        // 创建静音工具栏按钮项
        muteItem = new ToolItem(toolBar, SWT.CHECK);
        muteItem.setToolTipText(Messages.EsdkUCConvWindow_MUTE_CANCEL);
        muteItem.setImage(ImageFactory.loadImage(Display.getCurrent(),
                ImageFactory.MUTE));
        muteItem.setDisabledImage(ImageFactory.loadImage(Display.getCurrent(),
                ImageFactory.MUTE_DISABLED));
        addMuteItemListener(muteItem);

        secondDialPadItem = new ToolItem(toolBar, SWT.PUSH);
        secondDialPadItem.setToolTipText(Messages.DialPad);
        secondDialPadItem.setImage(ImageFactory.loadImage(Display.getCurrent(),
                ImageFactory.DIALPAD));
        secondDialPadItem.setDisabledImage(ImageFactory.loadImage(Display
                .getCurrent(), ImageFactory.DIALPAD_DISABLED));
        secondDialPad = new SecondDialPad(composite);
        secondDialPadItem.addListener(SWT.Selection, new Listener()
        {
            @Override
            public void handleEvent(Event event)
            {
                Shell dialPadShell = secondDialPad.getShell();
                Rectangle rect = secondDialPadItem.getBounds();
                Point pt = new Point(rect.x, rect.y + rect.height);// 计算窗口出现的起始位置
                pt = toolBar.toDisplay(pt);// 将该点转化为于屏幕的相对位置
                dialPadShell.setLocation(pt.x, pt.y);// 设置菜单显示的位置
                dialPadShell.open();
                dialPadShell.setFocus();
            }
        });

        // 创建"视频开启"工具按钮
        videoOpenItem = new ToolItem(toolBar, SWT.PUSH);
        videoOpenItem.setToolTipText(Messages.EsdkUCConvWindow_VIDEO);
        if (ConstantsDefines.IP_PHONE_MODE.equals(UCSettingsService
                .getPhoneJoinDev()))
        {
            videoOpenItem.setEnabled(false);
        }
        addVideoOpenItemListener(videoOpenItem);

        // 创建”添加联系人“工具按钮,定义为下拉式
        contactAddItem = new ToolItem(toolBar, SWT.DROP_DOWN);
        contactAddItem.setToolTipText(Messages.EsdkUCConvWindow_ADD_CONTACT);
        contactAddItem.setImage(ImageFactory.loadImage(Display.getCurrent(),
                ImageFactory.CONTACT_ADD));
        contactAddItem.setDisabledImage(ImageFactory.loadImage(Display
                .getCurrent(), ImageFactory.CONTACT_ADD_DISABLED));

        new ToolItem(toolBar, SWT.SEPARATOR); // 分隔线

        // 创建”挂断“工具按钮
        ToolItem callEndItem = new ToolItem(toolBar, SWT.PUSH);
        callEndItem.setToolTipText(Messages.EsdkUCConvWindow_CLOSE_CALL);
        callEndItem.setImage(ImageFactory.loadImage(Display.getCurrent(),
                ImageFactory.CALL_END));
        addCallEndItemListener(callEndItem);

        // 定义一个弹出式菜单，使用常量SWT.POP_UP
        final Menu contactAddMenu = new Menu(composite.getShell(), SWT.POP_UP);
        // "从联系人列表选择"的菜单项
        MenuItem addFromAddrBookItem = new MenuItem(contactAddMenu, SWT.PUSH);
        addFromAddrBookItem
                .setText(Messages.EsdkUCConvWindow_INVITE_FROM_CONTACTLIST);
        addFromAddrBookItem.addSelectionListener(new SelectionAdapter()
        {
            @Override
            public void widgetSelected(SelectionEvent arg0)
            {
                super.widgetSelected(arg0);
                PersonSelectDialog personDialog = new PersonSelectDialog(
                        Display.getDefault().getActiveShell());
                if (personDialog.open() == Window.OK)
                {
                    Person[] personsToInvite = PersonInviteUtil.getInstance()
                            .getSelectedPerson();
                    if (null != personsToInvite && personsToInvite.length > 0)
                    {
                        batchInvite(personsToInvite);
                    }
                    else
                    {
                        MessageDialog.openWarning(Display.getCurrent()
                                .getActiveShell(), Messages.TIPS,
                                Messages.EsdkUCConvWindow_NOPERSONTOINVITE);

                    }
                }
            }
        });
        new MenuItem(contactAddMenu, SWT.SEPARATOR); // 菜单项分隔线
        // "直接从号码邀请"的菜单项
        MenuItem addFromDirectNumberItem = new MenuItem(contactAddMenu,
                SWT.PUSH);
        addFromDirectNumberItem
                .setText(Messages.EsdkUCConvWindow_INVITE_BY_PHONE_NUM);
        addFromDirectNumberItem.addSelectionListener(new SelectionAdapter()
        {
            @Override
            public void widgetSelected(SelectionEvent arg0)
            {
                super.widgetSelected(arg0);

                InviteByNumberDialog numberDialog = new InviteByNumberDialog(
                        Display.getCurrent().getActiveShell());
                if (numberDialog.open() == Window.OK)
                {
                    String numberToInvite = PersonInviteUtil.getInstance()
                            .getNumberToInvite();
                    boolean isTelphone = PluginUtil
                            .checkTelephone(numberToInvite);
                    logger.debug("number " + numberToInvite + " is input");
                    if (isTelphone)
                    {
                        String ucAccount = UCService.getInstance()
                                .UC_SDK_GetUCAccount(numberToInvite);
                        int accountType = AccountType.UC_ACCOUNT;
                        if (StringUtil.isEmptyStr(ucAccount))
                        {
                            ucAccount = numberToInvite;
                            accountType = AccountType.UC_IPPHONE;
                        }
                        else
                        {
                            ucAccount = ucAccount.trim();
                        }
                        boolean ret = batchInvite(accountType, ucAccount);
                        if (ret)
                        {
                            Participant participant = new Participant();
                            participant.setUcAccount(ucAccount);
                            participant.setNumber(ucAccount);
                            participant.setCallNumType(accountType);
                            participant
                                    .setStatusInConf(MemStatusInCall.CONF_MEM_INVITING);
                            if (participantsMap.containsKey(ucAccount))
                            {
                                participants.getparticipants().remove(
                                        participantsMap.get(ucAccount));
                            }
                            participantsMap.put(ucAccount, participant);
                            participants.addparticipants(participant);
                            freshTable();
                        }
                        logger.debug("batchInvite ucAccount " + ucAccount
                                + " with " + ret);
                    }
                    else
                    {
                        MessageDialog.openError(Display.getDefault()
                                .getActiveShell(), Messages.ERROR_TIP,
                                Messages.EsdkUCConvWindow_INVALID_TEL_NUM);
                    }

                }
            }
        });
        // 为”添加联系人“下拉工具栏注册单击下拉箭头事件
        contactAddItem.addListener(SWT.Selection, new Listener()
        {
            @Override
            public void handleEvent(Event event)
            {
                // 如果触发的事件为单击按钮,获得”添加联系人“按钮所在坐标位置和大小，相对于父窗口
                Rectangle rect = contactAddItem.getBounds();
                Point pt = new Point(rect.x, rect.y + rect.height);// 计算菜单出现的起始位置
                pt = toolBar.toDisplay(pt);// 将该点转化为于屏幕的相对位置
                contactAddMenu.setLocation(pt.x, pt.y);// 设置菜单显示的位置
                contactAddMenu.setVisible(true);// 显示菜单
            }
        });

        toolBar.pack();
    }

    // 创建一个显示时间的Label
    private void createTimeLabel()
    {
        timeLabel = new Label(composite, SWT.LEFT);
        fd = new FormData();
        fd.top = new FormAttachment(0, 9);
        fd.left = new FormAttachment(toolBar, 10);
        fd.right = new FormAttachment(100, -10);
        timeLabel.setLayoutData(fd);
        timeLabel.setText(PluginUtil.getFormatTime((int) callTimes));

    }

    private void addHoldItemListener(final ToolItem item)
    {
        item.addSelectionListener(new SelectionAdapter()
        {
            public void widgetSelected(SelectionEvent e)
            {
                if (!isHold)
                {
                    // 这里调用UC SDK的呼叫保持服务接口
                    UCCallService.holdCall(true);

                    item.setImage(ImageFactory.loadImage(Display.getCurrent(),
                            ImageFactory.CALL_RESUME));
                    item.setDisabledImage(ImageFactory.loadImage(Display
                            .getCurrent(), ImageFactory.CALL_RESUME_DISABLED));
                }
                else
                {
                    // 这里调用UC SDK的呼叫保持释放服务接口
                    UCCallService.holdCall(false);

                    item.setImage(ImageFactory.loadImage(Display.getCurrent(),
                            ImageFactory.CALL_HOLD));
                    item.setDisabledImage(ImageFactory.loadImage(Display
                            .getCurrent(), ImageFactory.CALL_HOLD_DISABLED));
                }
                item.setSelection(false);
                isHold = !isHold;
            }
        });
    }

    private void addMuteItemListener(final ToolItem item)
    {
        item.addSelectionListener(new SelectionAdapter()
        {
            public void widgetSelected(SelectionEvent e)
            {
                if (!isMute)
                {
                    // 这里调用UC SDK的静音服务接口
                    if (UCCallService.mute(true))
                    {
                        item.setImage(ImageFactory.loadImage(Display
                                .getCurrent(), ImageFactory.MUTED));
                        item.setDisabledImage(ImageFactory.loadImage(Display
                                .getCurrent(), ImageFactory.MUTED_DISABLED));
                    }
                }
                else
                {
                    // 这里调用UC SDK的取消静音服务接口
                    if (UCCallService.mute(false))
                    {
                        item.setImage(ImageFactory.loadImage(Display
                                .getCurrent(), ImageFactory.MUTE));
                        item.setDisabledImage(ImageFactory.loadImage(Display
                                .getCurrent(), ImageFactory.MUTE_DISABLED));
                    }
                }
                item.setSelection(false);
                isMute = !isMute;
            }
        });
    }

    private void addVideoOpenItemListener(final ToolItem item)
    {
        item.addSelectionListener(new SelectionAdapter()
        {
            public void widgetSelected(SelectionEvent e)
            {
                if (!isVideo)
                {
                    if (isDisposed(videoArea))
                    {
                        createVideoControl();
                    }
                    // 这里调用UC SDK的语音升级视频服务接口
                    if (UCCallService.openVideoCall(videoParmas))
                    {
                        setStatusTip(Messages.ESDKUCCONVWINDOW_VIDEO_UPGRADE);
                    }
                }
                else
                {
                    // 移除视频
                    UCCallService.colseVideoCall();
                    closeVideoScreen();
                }
                composite.pack();
            }
        });
    }

    private void addCallEndItemListener(final ToolItem item)
    {
        item.addSelectionListener(new SelectionAdapter()
        {
            public void widgetSelected(SelectionEvent e)
            {
                // 这里调用UC SDK的结束呼叫服务接口
                endCall();
            }
        });
    }

    private void displayCallTime()
    {
        if (!isDisposed(composite))
        {
            Display defaultDisplay = Display.getDefault();
            if (null != defaultDisplay)
            {
                defaultDisplay.syncExec(new Runnable()
                {
                    @Override
                    public void run()
                    {
                        if (!isDisposed(timeLabel))
                        {
                            timeLabel.setText(PluginUtil
                                    .getFormatTime((int) callTimes));
                        }
                    }
                });
            }
        }
    }

    public void endCall()
    {
        // 这里调用UC SDK的结束呼叫服务接口
        UCCallService.endCall();
        closeContents();
    }

    private void createPartiListTable()
    {
        tableViewer = new TableViewer(composite, SWT.SINGLE
                | SWT.FULL_SELECTION);

        table = tableViewer.getTable();

        for (int i = 0; i < COLUMN_COUNT; i++)
        {
            TableColumn tc = new TableColumn(table, SWT.LEFT);
            if (0 == i || 1 == i)
            {
                tc.setWidth(18);
            }
            // 设置表头可移动，默认为false
            tc.setMoveable(true);
        }
        table.setHeaderVisible(false);
        tableViewer.setContentProvider(new TableContentProvider());
        tableViewer.setLabelProvider(new PartiTableLabelProvider());

        freshTable();

        createTableMenu();
    }

    public void freshTable()
    {
        if (null != composite && null != tableViewer)
        {
            tableViewer.setInput(participants.getparticipants());

            fd = new FormData();
            fd.top = new FormAttachment(divider_1, 0);
            fd.left = new FormAttachment(0, 0);
            fd.right = new FormAttachment(100, 0);
            if (!isVideo)
            {
                fd.bottom = new FormAttachment(statusBar, 0);
            }

            if (null != handler)
            {
                fd.width = handler.getShell().getBounds().width - 30;
            }
            else
            {
                fd.width = 345;
            }
            if (null != table)
            {
                if (null != handler)
                {
                    int height = composite.getSize().y - toolBar.getSize().y
                            - 25;

                    if (isVideo && null != videoArea)
                    {
                        height -= videoArea.getSize().y;
                    }

                    int row = height / table.getItemHeight();
                    if (height < 0 || row <= 1
                            || (isVideo && null != videoArea))
                    {
                        fd.height = table.getItemHeight() * 1;
                    }
                    else
                    {
                        fd.height = table.getItemHeight() * row;
                    }

                    fd.height -= 10;
                }
                else
                {
                    if (participants.size() >= 6)
                    {
                        fd.height = table.getItemHeight() * 6;
                    }
                }
                table.setLayoutData(fd);

                for (int i = 0; i < COLUMN_COUNT; i++)
                {
                    table.getColumn(i).pack();
                }
            }
            composite.pack();
        }
    }

    // 创建上下文菜单
    private void createTableMenu()
    {
        Menu menu = new Menu(table.getShell());
        menu.addMenuListener(new MenuListener()
        {
            @Override
            public void menuHidden(MenuEvent menuevent)
            {
            }

            @Override
            public void menuShown(MenuEvent menuevent)
            {
                Menu menu = (Menu) menuevent.getSource();
                MenuItem[] items = menu.getItems();
                for (int i = 0; items != null && i < items.length; i++)
                {
                    items[i].dispose();
                }
                if (table.getItemCount() <= 1)
                {
                    return;
                }
                if (CallMode.callIn == UCCallService.getCallMode())
                {
                    return;
                }

                // 获得当前的所选中的行
                StructuredSelection selection = (StructuredSelection) tableViewer
                        .getSelection();
                // 获得数组对象的一个元素，也就是只有选中一行的情况
                Participant participant = (Participant) selection
                        .getFirstElement();

                if (null != participant)
                {
                    int status = participant.getStatusInConf();
                    boolean isInConf = !(MemStatusInCall.CONF_MEM_HANGUP == status
                            || MemStatusInCall.CONF_MEM_QUIT == status || MemStatusInCall.CONF_MEM_DEL == status);

                    boolean isMute = (MemStatusInCall.CONF_MEM_MUTE == participant
                            .getStatusInConf());

                    if (0 != participants.getparticipants()
                            .indexOf(participant))
                    {
                        if (!isInConf)
                        {
                            createInviteMenuItem(menu, participant);
                        }
                        else
                        {
                            createRemoveMenuItem(menu, participant);
                        }
                    }

                    if (isInConf)
                    {
                        createModifyMemberStatusMenuItem(menu, isMute,
                                participant);
                    }
                }
            }
        });
        // 将该对象设置为表格的菜单
        table.setMenu(menu);
    }

    /**
     * 创建重新邀请与会人菜单
     * 
     * @param menu
     * @param isInConf
     * @param participant
     */
    private void createInviteMenuItem(Menu menu, final Participant participant)
    {
        MenuItem item = new MenuItem(menu, SWT.NONE);
        item.setText(Messages.EsdkUCConvWindow_REINVITE);
        item.addSelectionListener(new SelectionAdapter()
        {
            @Override
            public void widgetSelected(SelectionEvent arg0)
            {
                super.widgetSelected(arg0);
                boolean ret = false;
                int status = participant.getStatusInConf();
                if (MemStatusInCall.CONF_MEM_QUIT == status)
                {
                    // 成员退出，调用接口重新呼叫成员
                    ret = UCConfService.modifyMemberStatusInConf(
                            ConvnerOperateType.ReInviteMember, participant
                                    .getCallNumType(), participant
                                    .getUcAccount());
                }
                else
                {
                    // 成员呗删除，调用UC SDK的邀请与会人服务接口
                    ret = UCConfService.inviteMemberInConf(participant
                            .getCallNumType(), participant.getUcAccount());
                }
                if (ret)
                {
                    int index = participants.getparticipants().indexOf(
                            participant);
                    participant
                            .setStatusInConf(MemStatusInCall.CONF_MEM_INVITING);
                    participants.getparticipants().set(index, participant);
                    freshTable();
                }
            }
        });
    }

    /**
     * 创建请出与会人菜单
     * 
     * @param menu
     * @param isInConf
     * @param participant
     */
    private void createRemoveMenuItem(Menu menu, final Participant participant)
    {
        MenuItem item = new MenuItem(menu, SWT.NONE);
        item.setText(Messages.EsdkUCConvWindow_KICK_OUT_CONF);
        RemoveMemInConfAdpter removeAdpter = new RemoveMemInConfAdpter(
                participant);
        item.addSelectionListener(removeAdpter);
    }

    private void createModifyMemberStatusMenuItem(Menu menu,
            final boolean isMute, final Participant participant)
    {
        String itemTitle;
        if (isMute)
        {
            itemTitle = Messages.EsdkUCConvWindow_ALLOW_SPEAK;
        }
        else
        {
            itemTitle = Messages.EsdkUCConvWindow_FORBID_SPEAK;
        }
        MenuItem item = new MenuItem(menu, SWT.NONE);
        item.setText(itemTitle);
        MuteSelectionAdapter muteSelectionAdapter = new MuteSelectionAdapter(
                isMute, participant);
        item.addSelectionListener(muteSelectionAdapter);
    }

    private static class MuteSelectionAdapter extends SelectionAdapter
    {
        private boolean isMute;

        private Participant participant;

        public MuteSelectionAdapter(boolean muteValue,
                Participant participantParam)
        {
            this.isMute = muteValue;
            this.participant = participantParam;
        }

        @Override
        public void widgetSelected(SelectionEvent arg0)
        {
            super.widgetSelected(arg0);
            int operateType;
            if (isMute)
            {
                operateType = ConvnerOperateType.UnMuteMember;
            }
            else
            {
                operateType = ConvnerOperateType.MuteMember;
            }
            UCConfService.modifyMemberStatusInConf(operateType, participant
                    .getCallNumType(), participant.getUcAccount());
        }
    }

    private static class TableContentProvider implements
            IStructuredContentProvider
    {
        @Override
        public Object[] getElements(Object inputElement)
        {
            return ((List<?>) inputElement).toArray();
        }

        @Override
        public void dispose()
        {
        }

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
        {
        }

    }

    private class PartiTableLabelProvider implements ITableLabelProvider
    {
        @Override
        public Image getColumnImage(Object element, int columnIndex)
        {
            Participant participant = (Participant) element;
            Image statusImage = null;
            switch (columnIndex)
            {
                case IS_CHAIRMAN_COLUMN:

                    if (isConf
                            && 0 == participants.getparticipants().indexOf(
                                    participant))
                    {
                        statusImage = ImageFactory.loadImage(Display
                                .getCurrent(), ImageFactory.ICON_CONF_LEADER);
                    }
                    break;
                case UC_STATUS_COLUMN:

                    logger.debug(participant.getUcAccount() + " : "
                            + participant.getStatusInConf());
                    if (isConf)
                    {
                        // if (AccountType.UC_IPPHONE == participant
                        // .getCallNumType())
                        // {
                        // break;
                        // }
                        Image image = UCConfService
                                .getConfStatusImage(participant
                                        .getStatusInConf());
                        if (null != image)
                        {
                            ImageData statusImageData = image.getImageData();
                            ImageData scaledData = statusImageData.scaledTo(15,
                                    15);
                            statusImage = new Image(Display.getDefault(),
                                    scaledData);
                        }
                    }
                    else
                    {
                        ImageData statusImageData = UCCallService
                                .getCallStatusImage(
                                        UCCallService.getCallStatus())
                                .getImageData();
                        ImageData scaledData = statusImageData.scaledTo(15, 15);
                        statusImage = new Image(Display.getDefault(),
                                scaledData);
                    }
                    break;
                default:
                    break;
            }
            return statusImage;
        }

        @Override
        public String getColumnText(Object element, int columnIndex)
        {
            Participant participant = (Participant) element;
            String columnText = "";
            switch (columnIndex)
            {
                case PARTI_COLUMN:

                    columnText = participant.getNickname();
                    break;
                case NUMBER_COLUMN:

                    columnText = participant.getNumber();
                    break;
                default:
                    break;
            }
            return columnText;
        }

        @Override
        public void dispose()
        {
            // ImageFactory.dispose();
        }

        @Override
        public boolean isLabelProperty(Object element, String property)
        {
            return false;
        }

        @Override
        public void addListener(ILabelProviderListener listener)
        {

        }

        @Override
        public void removeListener(ILabelProviderListener listener)
        {

        }

    }

    private void createVideoControl()
    {
        videoArea = new Group(composite, SWT.NONE);
        localVideo = new Label(videoArea, SWT.NONE);
        remoteVideo = new Label(videoArea, SWT.NONE);
        setVideoParma();
    }

    private void createVideoScreenArea()
    {
        fd = new FormData();
        fd.top = new FormAttachment(table, 0);
        fd.left = new FormAttachment(0, 0);
        fd.right = new FormAttachment(100, 0);
        fd.bottom = new FormAttachment(statusBar, 0);
        fd.width = 350;
        fd.height = 350;
        videoArea.setLayoutData(fd);
        videoArea.setText(Messages.EsdkUCConvWindow_VIDEO_AREA);
        videoArea.setVisible(true);

        createLocatVideoArea();
        createRemoteVideoArea();
    }

    private void createLocatVideoArea()
    {
        localVideo.setBounds(180, 180, 180, 180);
        localVideo.setBackground(new Color(null, 0, 0, 0));
        localVideo.setVisible(true);
    }

    private void createRemoteVideoArea()
    {
        remoteVideo.setBounds(0, 0, 360, 360);
        remoteVideo.setBackground(new Color(null, 75, 75, 75));
        remoteVideo.setVisible(true);
    }

    private void setVideoParma()
    {
        STVideoWindow localWindow = new STVideoWindow();
        localWindow.hWnd = localVideo.handle;
        localWindow.top = 0;
        localWindow.left = 0;
        localWindow.width = 50;
        localWindow.height = 50;
        STVideoWindow remoteWindow = new STVideoWindow();
        remoteWindow.hWnd = remoteVideo.handle;
        remoteWindow.top = 50;
        remoteWindow.left = 50;
        remoteWindow.width = 50;
        remoteWindow.height = 50;

        logger.debug("localVideo.handle = " + localVideo.handle);
        logger.debug("remoteVideo.handle = " + remoteVideo.handle);
        videoParmas = new VideoFrameParmas(localWindow, remoteWindow);
    }

    /**
     * 添加视频显示区域
     */
    public void addVideoScreenArea()
    {
        logger.debug("addVideoScreenArea");
        isVideo = true;
        setVideoEnabled(true);
        createVideoScreenArea();

        setStatusTip(Messages.EsdkUCConvWindow_CALL_CONNECTED);

        composite.pack();

        freshTable();
    }

    /**
     * 移除视频显示区域
     */
    public void closeVideoScreen()
    {
        logger.debug("closeVideoScreen");
        isVideo = false;
        setVideoEnabled(false);
        if (!isDisposed(videoArea))
        {
            if (!isDisposed(remoteVideo))
            {
                remoteVideo.dispose();
                remoteVideo = null;
            }
            if (!isDisposed(localVideo))
            {
                localVideo.dispose();
                localVideo = null;
            }

            videoArea.dispose();
            videoArea = null;
        }

        setStatusTip(Messages.EsdkUCConvWindow_CALL_CONNECTED);
        composite.pack();

        freshTable();
    }

    private void createStatusbar()
    {
        if (null != statusBar)
        {
            statusBar.dispose();
        }

        statusBar = new Label(composite, SWT.BORDER);
        fd = new FormData();
        fd.top = new FormAttachment(100, -20);
        fd.left = new FormAttachment(0, 0);
        fd.right = new FormAttachment(100, 0);
        fd.bottom = new FormAttachment(100, 0);
        // fd.height = 15;
        statusBar.setLayoutData(fd);
        // 如果不是会议,则是语音或者视频呼叫,这个时候才需要设置状态栏文字
        if (!isConf)
        {
            // 创建一个用于显示文字的标签
            statusBar.setText(Messages.EsdkUCConvWindow_CONNECTED);
        }
        statusBar.setVisible(true);
    }

    /**
     * 更新状态栏上的提示文字
     */
    public void setStatusTip(String tipsStr)
    {
        if (!isDisposed(statusBar))
        {
            logger.debug("setStatusTip tipsStr = " + tipsStr);
            statusBar.setText(tipsStr);
        }
    }

    public void setVideoEnabled(boolean isVideo)
    {
        logger.debug("setVideoEnabled isVideo = " + isVideo);
        this.isVideo = isVideo;
        if (!isDisposed(composite) && !isDisposed(videoOpenItem))
        {
            if (isVideo)
            {
                videoOpenItem.setImage(ImageFactory.loadImage(Display
                        .getCurrent(), ImageFactory.VIDEO_OFF));
            }
            else
            {
                videoOpenItem.setImage(ImageFactory.loadImage(Display
                        .getCurrent(), ImageFactory.VIDEO_ON));
            }
        }
        setHoldItemEnabled();
        setContactAddItemEnabled();

        if (!isDisposed(composite) && !isDisposed(toolBar))
        {
            toolBar.pack();
        }
    }

    private void setHoldItemEnabled()
    {
        if (!isDisposed(composite) && !isDisposed(holdItem))
        {
            if (isVideo || isConf)
            {
                holdItem.setEnabled(false);
            }
            else
            {
                holdItem.setEnabled(true);
            }
        }
    }

    private void setContactAddItemEnabled()
    {
        if (!isDisposed(composite) && !isDisposed(contactAddItem))
        {
            if (isVideo || CallMode.callIn == UCCallService.getCallMode())
            {
                contactAddItem.setEnabled(false);
            }
            else
            {
                contactAddItem.setEnabled(true);
            }
        }
    }

    /**
     * 更新会议中成员的状态
     * 
     * @param arg0
     */
    public synchronized void updateMembersInConf(STConfParam confParam)
    {
        logger.debug("updateMembersInConf");
        setConfEnabled(true);
        Participant confMember;
        String ucAccount = StringUtil.bytesToString(confParam.ucAcc);
        String number = ucAccount;
        int memStatus = confParam.memStatus;
        int accountType = confParam.memType;

        int index = 0;

        if (PhoneJointType.IPPhone_Device == accountType)
        {
            logger.debug("PhoneJointType.IPPhone_Device");
            String ucAccountTemp = UCService.getInstance().UC_SDK_GetUCAccount(
                    ucAccount);
            if (!StringUtil.isEmptyStr(ucAccountTemp))
            {
                ucAccount = ucAccountTemp.trim();
                logger.debug("ucAccount = " + ucAccount);
            }
        }
        if (!participantsMap.containsKey(ucAccount))
        {
            logger.debug("participantsMap is not contain " + "ucAccount = "
                    + ucAccount);
            confMember = new Participant();
            confMember.setUcAccount(ucAccount);
            confMember.setNumber(number);
            confMember.setCallNumType(accountType);
            confMember.setStatusInConf(memStatus);

            participantsMap.put(ucAccount, confMember);
            participants.addparticipants(confMember);
        }
        else
        {
            logger.debug("participantsMap is contain " + "ucAccount = "
                    + ucAccount);

            confMember = participantsMap.get(ucAccount);

            index = participants.getparticipants().indexOf(confMember);
            confMember.setStatusInConf(memStatus);
            confMember.setCallNumType(accountType);
            participants.getparticipants().set(index, confMember);
        }

        if (MemStatusInCall.CONF_MEM_DEL == memStatus)
        {
            participantsMap.remove(ucAccount);
            participants.getparticipants().remove(confMember);
        }

        // if (!participantsMap.containsKey(ucAccount)
        // && MemStatusInCall.CONF_MEM_QUIT != memStatus
        // && MemStatusInCall.CONF_MEM_DEL != memStatus)
        // {
        // confMember = new Participant();
        // confMember.setUcAccount(ucAccount);
        // confMember.setNumber(ucAccount);
        // confMember.setCallNumType(accountType);
        // confMember.setStatusInConf(memStatus);
        // participantsMap.put(ucAccount, confMember);
        // participants.addparticipants(confMember);
        // }
        // else
        // {
        // confMember = participantsMap.get(ucAccount);
        //
        // if (MemStatusInCall.CONF_MEM_DEL == memStatus)
        // {
        // participantsMap.remove(ucAccount);
        // participants.getparticipants().remove(confMember);
        // }
        // else
        // {
        // index = participants.getparticipants().indexOf(confMember);
        // confMember.setStatusInConf(memStatus);
        // confMember.setCallNumType(accountType);
        // participants.getparticipants().set(index, confMember);
        // }
        // }

        if (CallMode.callOut == UCCallService.getCallMode())
        {
            if (PluginUtil.getLocalUcAccount().equals(ucAccount))
            {
                participants.getparticipants().remove(confMember);
                participants.getparticipants().add(0, confMember);
            }
        }

        setConentTitle();

        freshTable();
    }

    public void setConfEnabled(boolean isConf)
    {
        this.isConf = isConf;
        if (isConf)
        {
            isVideo = false;
            if (!isDisposed(composite) && !isDisposed(videoOpenItem)
                    && !isDisposed(holdItem))
            {
                videoOpenItem.setEnabled(false);
                videoOpenItem.setImage(ImageFactory.loadImage(Display
                        .getCurrent(), ImageFactory.VIDEO_ON));
                videoOpenItem.setDisabledImage(ImageFactory.loadImage(Display
                        .getCurrent(), ImageFactory.VIDEO_ON_DISABLED));

                setHoldItemEnabled();

                composite.pack();
            }
        }
    }

    public Composite getComposite()
    {
        return composite;
    }

    public boolean isDisposed(Widget widget)
    {
        if (null == widget)
        {
            return true;
        }
        return widget.isDisposed();
    }

    public void callStart()
    {
        if (null == callTimer)
        {
            callTimer = new Timer();
            callTimer.schedule(new TimerTask()
            {
                @Override
                public void run()
                {
                    callTimes++;
                    displayCallTime();
                }
            }, 0, 1000);
        }
    }

    public void callStop()
    {
        if (null != callTimer)
        {
            callTimer.cancel();
            callTimer = null;
            callTimes = 0;
            displayCallTime();
        }
    }

    public long getCallTimes()
    {
        return callTimes;
    }

    private boolean batchInvite(int accountType, String ucAccount)
    {
        logger.debug("batchInvite : " + ucAccount);

        if (PluginUtil.getLocalUcAccount().equals(ucAccount))
        {
            return false;
        }

        if (participantsMap.containsKey(ucAccount))
        {
            Participant participant = participantsMap.get(ucAccount);
            int status = participant.getStatusInConf();
            boolean isInConf = !(MemStatusInCall.CONF_MEM_HANGUP == status
                    || MemStatusInCall.CONF_MEM_QUIT == status || MemStatusInCall.CONF_MEM_DEL == status);
            if (isInConf)
            {
                return false;
            }
        }

        // 成员被删除，调用UC SDK的邀请与会人服务接口
        boolean ret = UCConfService.inviteMemberInConf(accountType, ucAccount);

        if (!ret)
        {
            // 成员退出，调用接口重新呼叫成员
            ret = UCConfService.modifyMemberStatusInConf(
                    ConvnerOperateType.ReInviteMember, accountType, ucAccount);
        }

        return ret;

    }

    private void batchInvite(Person[] personsToInvite)
    {
        setConfEnabled(true);

        boolean ret = false;
        String ucAccount = null;
        Participant participant;
        for (Person person : personsToInvite)
        {
            ucAccount = PluginUtil.getUCAccountFromContactID(person
                    .getContactId());

            ret = batchInvite(AccountType.UC_ACCOUNT, ucAccount);
            if (ret)
            {
                participant = new Participant();
                participant.setUcAccount(ucAccount);
                participant.setNumber(ucAccount);
                participant.setCallNumType(AccountType.UC_ACCOUNT);
                participant.setStatusInConf(MemStatusInCall.CONF_MEM_INVITING);
                if (participantsMap.containsKey(ucAccount))
                {
                    participants.getparticipants().remove(
                            participantsMap.get(ucAccount));
                }
                participantsMap.put(ucAccount, participant);
                participants.addparticipants(participant);
                freshTable();
            }
            logger.debug("batchInvite ucAccount " + ucAccount + " with " + ret);
        }
    }

    private static class RemoveMemInConfAdpter extends SelectionAdapter
    {
        private Participant participant;

        public RemoveMemInConfAdpter(Participant participant)
        {
            this.participant = participant;
        }

        @Override
        public void widgetSelected(SelectionEvent arg0)
        {
            super.widgetSelected(arg0);

            UCConfService.modifyMemberStatusInConf(
                    ConvnerOperateType.EndCallMember, participant
                            .getCallNumType(), participant.getUcAccount());

        }
    }
}
